// pages/me/me.js
//获取应用实例
const app = getApp()

Page({
  data: {
    list: [
      [
        {
          text: '账号与安全',
          icon: '/images/icon01.png',
          input:'',
          content:'',
          content_1:'昵称:',
          content_2:'性别:',
          content_3:'生日:',
          content_4:'签名:'
        }
      ],
      [
        {
          text: '隐私政策',
          icon: '/images/icon03.png',
          input:'',
          content:'樱花是由董婵、吴鸿羽、徐嘉怡共同完成的一款旅游小程序。隐私权是每个人的重要权利，樱花非常注重用户个人信息和隐私政策的保护......',
          content_1:'',
          content_2:'',
          content_3:'',
          content_4:''
        }
      ],
      [
        {
          text: '帮助与反馈',
          icon: '/images/icon05.png',
          input:'请输入您要反馈的内容',
          content:'',
          content_1:'',
          content_2:'',
          content_3:'',
          content_4:''
        }
      ],
      [
        {
          text: '关于APP',
          icon: '/images/icon04.png',
          input:'',
          content:'樱游是一款旅行软件，可以给人们提供专业的线路规划。只要遵照app内制定的旅游手册，就能来一场说走就走的旅行',
          content_1:'',
          content_2:'',
          content_3:'',
          content_4:''
        }
      ]
    ],

    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
  },

  //事件处理函数
  bindViewTap: function () {
    wx.navigateTo({
      url: '/pages/me/like/like'
    })
  },

  onLoad: function () {
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse) {
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  },

  getUserInfo: function (e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },

  navbarTap: function (e) {

    this.setData({
      currentTab: e.currentTarget.dataset.idx
    })

  },

  listChange: function (e) {
    var that = this;
    console.log(e.currentTarget.dataset)
    var text = e.currentTarget.dataset.list.text
    var content = e.currentTarget.dataset.list.content
    var content_1 = e.currentTarget.dataset.list.content_1
    var content_2 = e.currentTarget.dataset.list.content_2
    var content_3 = e.currentTarget.dataset.list.content_3
    var content_4 = e.currentTarget.dataset.list.content_4
    var input = e.currentTarget.dataset.list.input
    wx.navigateTo({
      url: '../me/list/list?text=' + text + '&content=' + content + '&content_1=' + content_1 + '&content_2=' + content_2 + '&content_3=' + content_3 + '&content_4=' + content_4 + '&input=' + input
    })
  }
})